home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS03.ADF
/
Xref
/
getch.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-04-02
|
1KB
|
64 lines
/**************************************************************************
NAME
getch/ungetch -- buffered use of getchar allowing "push-back"
SYNOPSIS
c = getch(); get character from file
int c; next input character or EOF
ungetch(c); push character back on input
int c; character to be output
DESCRIPTION
Use getch in lieu of getchar when it is desirable to reread an
unwanted character later. Use ungetch to "push back" the
unwanted character for the next use of getch.
RETURNS
c = character
= EOF if end-of-file or error
CAUTIONS
Buffer will hold only 100 characters.
AUTHOR Philip T. Ansteth
DATE Nov. 19, 1985
CLIENT ANSTETH RESEARCH
CALLED FUNCTIONS
getchar get character from file
UPDATE HISTORY
**************************************************************************/
#include <stdio.h>
#define BUFSIZE 100
char buf[BUFSIZE]; /* buffer for ungetch */
int bufp = 0; /* next free position in buf */
getch() /* get a (possibly pushed back) character */
{
return((bufp > 0) ? buf[--bufp] : getchar());
}
ungetch(c) /* push character back on input */
int c;
{
if (bufp > BUFSIZE)
printf("ungetch: too many characters\n");
else
buf[bufp++] = c;
}